package com.eos.control.action.emp;

import com.eos.business.service.SysUserBusinessService;
import com.eos.common.tool.ConstantTool;
import com.eos.common.tool.DataCacheUtil;
import com.eos.common.tool.ObjectUtils;
import com.eos.control.action.base.AbstractBaseAction;
import com.eos.orm.mybatis.model.SysMenu;

public class SaveFunctionAction extends AbstractBaseAction {
	private static final long serialVersionUID = -3686997916236392171L;
	private Integer menuId;
	private String menuUrl;
	private String menuName;
	private String menuDesc;
	private String webMk;
	private Integer parentId;
	
	public void setMenuId(Integer menuId) {
		this.menuId = menuId;
	}

	public void setMenuUrl(String menuUrl) {
		this.menuUrl = menuUrl;
	}

	public void setMenuName(String menuName) {
		this.menuName = menuName;
	}

	public void setMenuDesc(String menuDesc) {
		this.menuDesc = menuDesc;
	}

	public void setParentId(Integer parentId) {
		this.parentId = parentId;
	}

	public void setWebMk(String webMk) {
		this.webMk = webMk;
	}

	@Override
	public String execute() {
		try {
			String strTime = ObjectUtils.formatDate(null, "yyyy-MM-dd HH:mm:ss");
			SysMenu menu = new SysMenu();
			String exeStatus = "";
			SysUserBusinessService sbs = new SysUserBusinessService();
			if ("I".equals(webMk)) {
				menu.setMenuDesc(menuDesc);
				menu.setMenuLevel(0);
				menu.setMenuName(menuName);
				menu.setMenuOrder(0);
				menu.setMenuUrl(menuUrl);
				menu.setInsertTime(strTime);
				menu.setModifyTime(strTime);
				menu.setParentId(parentId);
				menu.setStatus(ConstantTool.STATUS_OK);
				menu.setDealFlag(ConstantTool.DEAL_FALG_OK);
				exeStatus = sbs.saveSysMenu(menu);
				message = "新增菜单成功!";
			} else if ("U".equals(webMk)) {
				menu.setId(menuId);
				menu.setMenuUrl(menuUrl);
				menu.setMenuName(menuName);
				menu.setMenuDesc(menuDesc);
				exeStatus = sbs.updateSysMenuSelective(menu);
				message = "修改菜单信息成功!";
			} else if ("D".equals(webMk)) {
				menu.setId(menuId);
				menu.setDealFlag(ConstantTool.DEAL_FLAG_FAIL);
				menu.setModifyTime(strTime);
				exeStatus = sbs.updateSysMenuSelective(menu);
				message = "删除菜单成功!";
			}
			if("SUCCESS".equals(exeStatus)){
				DataCacheUtil.clearSysMenuMap();
				DataCacheUtil.clearViewRoleMenuMap();
				statusCode = "200";
			}else{
				message = "系统繁忙, 操作失败!";
				statusCode = "300";
			}
			
		} catch (Exception ex) {
			ex.printStackTrace();
			statusCode = "300";
			message = "系统异常,操作失败!";
		}
		return SUCCESS;
	}
}
